# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=grpc-pentest-suite
pkgver=104.93bd7bc
pkgrel=2
pkgdesc='Set of tools for pentesting gRPC-Web Applications.'
arch=('any')
groups=('blackarch' 'blackarch-webapp' 'blackarch-recon' 'blackarch-scanner')
url='https://github.com/nxenon/grpc-pentest-suite'
license=('GPL-3.0-or-later')
depends=('python' 'python-editorconfig' 'python-jsbeautifier' 'python-six'
         'python-texttable' 'python-wcwidth')
makedepends=('git')
source=("git+https://github.com/nxenon/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -Dm 644 requirements.txt "$pkgdir/usr/share/$pkgname/requirements.txt"
  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" *.md

  rm -rf LICENSE *.md .gitignore

  cp -a * "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/grpc-coder" << EOF
#!/bin/sh
exec python /usr/share/$pkgname/grpc_coder.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/grpc-coder"

  cat > "$pkgdir/usr/bin/grpc-scan" << EOF
#!/bin/sh
exec python /usr/share/$pkgname/grpc_scan.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/grpc-scan"

  cat > "$pkgdir/usr/bin/big-string-chunker" << EOF
#!/bin/sh
exec python /usr/share/$pkgname/big_string_chunker.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/big-string-chunker"
}

